import os
import sys
import numpy as np
from scipy.io import loadmat
import matplotlib.pyplot as plt

'''
m=loadmat("statlearning-sjtu-2020/ECGTestData/ECGTestData/88247.mat")
bData=m['data']
bData=bData.T
for i in range(1,len(bData)):
    pipe=bData[i]
    x=np.arange(0,len(pipe),1)
    plt.plot(x,pipe)
    plt.show()
'''

'''
data=loadmat("statlearning-sjtu-2020/ECGTrainData/Train/窦性心动过缓/71632.mat")
beats=data['Beats'][0][0]
j=2
bdata=beats[3][0][j]
bdata=bdata.T
for i in range(len(bdata)):
    pipe=bdata[i]
    x=np.arange(0,len(pipe),1)
    plt.plot(x,pipe)
    plt.show()
'''

'''
data=loadmat("statlearning-sjtu-2020/ECGTrainData/Train/正常心电图/60104.mat")
beats=data['Beats'][0][0]
print(type(beats[3]),beats[3].shape)#,beats[3])
i=3; j=21
print(type(beats[i][0][j]),beats[i][0][j].shape,beats[i][0][j])
data=loadmat("statlearning-sjtu-2020/ECGTestData/ECGTestData/88247.mat")
print(data.keys())
print(type(data['data']).__name__,data['data'])

tdata=loadmat("statlearning-sjtu-2020/ECGTestData/ECGTestData/814358.mat")
dataitem=tdata['data']
print(type(dataitem),dataitem.shape)
'''

'''
import PIL.Image as Image
import os

IMAGES_PATH = './'  # 图片集地址
IMAGES_FORMAT = ['.png']  # 图片格式
IMAGE_SIZE = 1000  # 每张小图片的大小
IMAGE_ROW = 3  # 图片间隔，也就是合并成一张图后，一共有几行
IMAGE_COLUMN = 4  # 图片间隔，也就是合并成一张图后，一共有几列
IMAGE_SAVE_PATH = './grid.jpg'  # 图片转换后的地址

# 获取图片集地址下的所有图片名称
image_names = [name for name in os.listdir(IMAGES_PATH) for item in IMAGES_FORMAT if
               os.path.splitext(name)[1] == item]

# 简单的对于参数的设定和实际图片集的大小进行数量判断
print(image_names)
if len(image_names) != IMAGE_ROW * IMAGE_COLUMN:
    raise ValueError("合成图片的参数和要求的数量不能匹配！")


# 定义图像拼接函数
def image_compose():
    to_image = Image.new('RGB', (IMAGE_COLUMN * IMAGE_SIZE, IMAGE_ROW * IMAGE_SIZE))  # 创建一个新图
    # 循环遍历，把每张图片按顺序粘贴到对应位置上
    for y in range(1, IMAGE_ROW + 1):
        for x in range(1, IMAGE_COLUMN + 1):
            from_image = Image.open(IMAGES_PATH + image_names[IMAGE_COLUMN * (y - 1) + x - 1]).resize(
                (IMAGE_SIZE, IMAGE_SIZE), Image.ANTIALIAS)
            to_image.paste(from_image, ((x - 1) * IMAGE_SIZE, (y - 1) * IMAGE_SIZE))
    return to_image.save(IMAGE_SAVE_PATH)  # 保存新图

image_compose()  # 调用函数

'''

